//
//  main.m
//  TestCopy
//
//  Created by YC on 2017/6/12.
//  Copyright © 2017年 YC. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "NSArray+DeepCopy.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        

        NSMutableString *mStr = [NSMutableString stringWithFormat:@"123"];
        NSMutableArray *element = [NSMutableArray arrayWithObjects:@1,mStr,nil];
        NSMutableArray *array = [NSMutableArray arrayWithObject:element];
        
        NSMutableArray *copyArray = [array copy];
        NSMutableArray *mutableCopyArray = [array mutableCopy];
        //不完全深拷贝
        NSMutableArray *deepCopyArray = [[NSMutableArray alloc] initWithArray:array copyItems:true];
        //完全深拷贝
        NSMutableArray *realDeepCopyArray = [array mutableDeepCopy];
        
        [mutableCopyArray[0] addObject:@2];
        [mutableCopyArray[0][1] appendString:@"123"];
        //element变为不可变了
//        [deepCopyArray[0] addObject:@3];
        [deepCopyArray[0][1] appendString:@"123"];
        
        NSLog(@"array---%@,p---%p",array,array);
        NSLog(@"copyArray---%@,p---%p",copyArray,copyArray);
        NSLog(@"mutableCopyArray---%@,p---%p",mutableCopyArray,mutableCopyArray);
        NSLog(@"deepCopyArray---%@,p-%p",deepCopyArray,deepCopyArray);
        NSLog(@"realDeepCopyArray---%@,p-%p",realDeepCopyArray,realDeepCopyArray);
        
        NSLog(@"array本身:%@---%p",[array class],array);
        for (int i = 0; i < array.count; i++) {
            NSLog(@"array第%d层:%@---%p",i,[array[i] class],array[i]);
            
            for (id obj in array[i]) {
                NSLog(@"i层内部---%p",obj);
            }
        }
        
        NSLog(@"copyArray本身:%@---%p",[copyArray class],copyArray);
        for (int i = 0; i < copyArray.count; i++) {
            NSLog(@"copyArray第%d层:%@---%p",i,[copyArray[i] class],copyArray[i]);
            
            for (id obj in copyArray[i]) {
                NSLog(@"i层内部---%p",obj);
            }
        }
        
        NSLog(@"mutableCopyArray本身:%@---%p",[mutableCopyArray class],mutableCopyArray);
        for (int i = 0; i < mutableCopyArray.count; i++) {
            NSLog(@"mutableCopyArray第%d层:%@---%p",i,[mutableCopyArray[i] class],mutableCopyArray[i]);
            
            for (id obj in mutableCopyArray[i]) {
                NSLog(@"i层内部---%p",obj);
            }
        }
        
        NSLog(@"deepCopyArray本身:%@---%p",[deepCopyArray class],deepCopyArray);
        for (int i = 0; i < deepCopyArray.count; i++) {
            NSLog(@"deepCopyArray第%d层:%@---%p",i,[deepCopyArray[i] class],deepCopyArray[i]);
            
            for (id obj in deepCopyArray[i]) {
                NSLog(@"i层内部---%p",obj);
            }
        }
        
        NSLog(@"realDeepCopyArray本身:%@---%p",[realDeepCopyArray class],realDeepCopyArray);
        for (int i = 0; i < realDeepCopyArray.count; i++) {
            NSLog(@"realDeepCopyArray第%d层:%@---%p",i,[realDeepCopyArray[i] class],realDeepCopyArray[i]);
            
            for (id obj in realDeepCopyArray[i]) {
                NSLog(@"i层内部---%p",obj);
            }
        }
        
    }
    return 0;
}

